$(document).ready(function(){
	layoutLoad("control");
	
	$("#auth_add > li > a").each(function( index ) {
		$(this).on("click", function(event){
			layoutLoad($(this).attr("id"));
		});
	});
	
	$(".btn_close").on("click", function(event) {
		window.close();
	});
	
	$(".btn_cancle").on("click", function(event) {
		window.close();
	});
	
	$(".btn_save").on("click", function(event) {
		var url = "insertObjectPopup.jsp";
		var serviceName = "OBJECT_ADD";
		var param = {
				command : $("#command").val(),
				auth_list : $("#auth_list").val(),
				ex : $("#ex").val()
		};
		callAjax(url,param, serviceName);
	});
});


function layoutLoad(id) {
	var url = getUrl()+"object_add_"+id+".jsp";
	$(".layer_cont").load(url, function() {
		$("#auth_add > li > a").each(function( index ) {
			var eachId = $(this).attr("id");
			if( id == eachId ) {
				$(this).addClass("on");
			} else {
				$(this).removeClass("on");
			}
		});
				
		if( id == "system" ) {
			loadTree("system");
		}
		
		/* info + 클릭시 */
		$("#btn_add_info_list").on("click", function(event) {
			var url = "../command/insertAuth.jsp";
			var serviceName = "AUTH_ADD";
			var param = {
					auth_list : $("#auth_list").val(),
					auth_type1 : $("#auth_type1 option:selected").val(),
					auth_type2 : $("#auth_type2 option:selected").val()
			};
			callAjax(url,param, serviceName);
		});
		/* info - 클릭시 */
		$("#btn_del_info_list").on("click", function(event) {
			var url = "../command/deleteAuth.jsp";
			var serviceName = "AUTH_DEL";
			var param = {
					auth_list : $("#auth_list").val(),
					auth_type1 : $("#auth_type1 option:selected").val(),
					auth_type2 : $("#auth_type2 option:selected").val()
			};
			callAjax(url,param, serviceName);
		});
	});
}


/* callAjax successAjax */
function successAjax(data, serviceName){
	if(serviceName == "OBJECT_ADD"){
		alert(data.result);
	}else if(serviceName == "OBJECT_ADD_TREE"){
		
	}else if(serviceName == "AUTH_ADD"){
		alert(data.result);
	}else if(serviceName == "AUTH_DEL"){
		alert(data.result);
	}
}

